﻿using Application.Interfaces.Repository;
using Domain.Core;
using System.Linq;

namespace Application.Core
{
    public sealed class CommonService<T> : BaseService, ICommonService<T> where T : BaseEntity
    {
        private IRepository<T> _repo;

        public CommonService(IRepository<T> repo)
        {
            this._repo = repo;
        }

        public T FindById(int id)
        {
            return _repo.FindById(id);
        }

        public IQueryable<T> Find()
        {
            return _repo.Find();
        }

        public void Add(T entity)
        {
            _repo.Add(entity);
            _repo.SaveChanges();
        }

        public void Update(T entity)
        {
            ///_repo.Update(entity);
            _repo.SaveChanges();
        }

        public void Remove(int id)
        {
            _repo.Remove(_repo.FindById(id));
            _repo.SaveChanges();
        }
    }
}